//
//  ChatConfig.swift
//  WeChat
//
//  Created by mac on 2018/8/24.
//  Copyright © 2018年 RRC. All rights reserved.
//

import Foundation
import UIKit

open class ChatConfig {
    
    
    /// 获取缩略图尺寸
    ///
    /// - Parameter originalSize: 原始图的尺寸 size
    /// - Returns: 返回的缩略图尺寸
    class func getThumbImageSize(_ originalSize: CGSize) -> CGSize {
        let imageRealHeight = originalSize.height
        let imageRealWidth = originalSize.width
        
        var resizeThumbWidth: CGFloat
        var resizeThumbHeight: CGFloat
        
        /**
        * 1)如果图片的高度 >= 图片的宽度， 高度就是最大的高度，宽度等比
        * 2)如果图片的高度 < 图片的宽度，以宽度来做等比，算出高度
         */
        
        if imageRealHeight >= imageRealWidth {
            let scaleWidth = imageRealWidth * kChatImageMaxHeight / imageRealHeight
            resizeThumbWidth = (scaleWidth > kChatImageMinWidth) ? scaleWidth : kChatImageMinWidth
            resizeThumbHeight = kChatImageMaxHeight
        }else{
            let scaleHeight = imageRealHeight * kChatImageMaxWidth / imageRealWidth
            resizeThumbHeight = (scaleHeight > kChatImageMinHeight) ? scaleHeight : kChatImageMinHeight
            resizeThumbWidth = kChatImageMaxWidth
        }
        return CGSize(width: resizeThumbWidth, height: resizeThumbHeight)
    }
    
}
